/**
 *
 */
package com.pocketsweet.service;

import java.util.ArrayList;

import org.json.JSONException;
import org.json.JSONObject;

import com.easemob.chat.EMMessage;
import com.pocketsweet.MLApplication;
import com.pocketsweet.MLCache;
import com.pocketsweet.MLContext;
import com.pocketsweet.chatlib.controller.MolianContactManager;
import com.pocketsweet.chatui.utils.CommonUtils;
import com.pocketsweet.ui.Main;
import com.pocketsweet.ui.NewFollow;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

/**
 * @author hantian
 */
public class PushReceiver extends BroadcastReceiver {
    static final String NEW_SYSYTEM_MASS_PUSH = "com.pocketsweet.NEW_SYSYTEM_MASS_PUSH";
    public static final String NEW_RECOMMEND_PUSH = "com.pocketsweet.NEW_RECOMMEND_PUSH";
    public static final String NEW_CUSTOMAZITION_PUSH = "com.pocketsweet.NEW_CUSTOMAZITION_PUSH";
    public static final String NEW_CALL_PUSH = "com.pocketsweet.NEW_CALL_PUSH";
    public static final String NEW_LIKE_PUSH = "com.pocketsweet.NEW_LIKE_PUSH";


    // private static ArrayList<NewPushListener> NewPushListener;

    @Override
    public void onReceive(Context context, Intent intent) {
        // 有消息的时候进行通知
        String action = intent.getAction();
        // 当收到系统的群发消息的通知
        if (action.equals(NEW_SYSYTEM_MASS_PUSH)) {
            try {
                // 获取消息内容
                JSONObject json = new JSONObject(intent.getExtras().getString(
                        "com.avos.avoscloud.Data"));
                final String msg = json.getString("msg");
                MolianContactManager.getInstance().onNewSysMsg(msg);
            } catch (JSONException e) {
                // Log.d(TAG, "JSONException: " + e.getMessage());
            }

        } else if (action.equals(NEW_RECOMMEND_PUSH)) {
            // 新的推荐
            try {
                // 获取消息内容
                JSONObject json = new JSONObject(intent.getExtras().getString(
                        "com.avos.avoscloud.Data"));
                final String msg = json.getString("alert");
                MolianContactManager.getInstance().onNewRecommedPush(msg);
            } catch (JSONException e) {
                // Log.d(TAG, "JSONException: " + e.getMessage());
            }
        } else if (action.equals(NEW_CUSTOMAZITION_PUSH)) {
            // 新的恋爱呼叫
            try {
                // 获取消息内容
                JSONObject json = new JSONObject(intent.getExtras().getString(
                        "com.avos.avoscloud.Data"));
                final String msg = json.getString("alert");
                MolianContactManager.getInstance().onNewCustomizationPush(msg);
            } catch (JSONException e) {
                // Log.d(TAG, "JSONException: " + e.getMessage());
            }
        }else if (action.equals(NEW_CALL_PUSH)) {

        }else if (action.equals(NEW_LIKE_PUSH)) {

        }
    }
}
